"""
des: 软件配置文件
author: mr_52hz
date: 2024-04-28
"""
import os
from PyQt5.QtCore import QSettings

BASE_DIR = os.path.dirname(os.path.abspath(__file__))

is_debug = False

DOCUMENTS_DIR = os.path.join(os.environ['USERPROFILE'], 'Documents')
DESKTOP_DIR = os.path.join(os.environ['USERPROFILE'], 'Desktop')

APP_DIR = os.path.join(DOCUMENTS_DIR, 'SmartTools')
if not os.path.exists(APP_DIR):
    os.makedirs(APP_DIR)

q_st = QSettings(os.path.join(APP_DIR, 'config.ini'), QSettings.IniFormat)


def load_conf(conf_key, default, _type):
    """
    加载本地配置
    :param conf_key: TOOL/FRAME_RATE 配置key值
    :param default: 配置默认值
    :param _type: 配置类型 int str
    :return: value
    """
    value = q_st.value(conf_key, False)
    if value is False:
        q_st.setValue(conf_key, default)
        value = default
    else:
        try:
            value = _type(value)
        except Exception:
            value = default

    return value


VERSION = 'V0.0.2-Beta'
AUTHOR = load_conf('MSG/Author', 'mr52hz', str)
SOFTWARE_NAME = 'SmartTools'

q_st.setValue('MSG/Software', SOFTWARE_NAME+VERSION)
q_st.setValue('MSG/Author', AUTHOR)

TENCENT_ID = 'AKID61LUUODsaIqJc7rU4Ys46HPTUO7oKrCV'
TENCENT_KEY = 'Hj5Vn1RoHnF31BCKcEpOn25GOgtAWpxE'

# img to pdf 支持的图像格式
support_img_format_str = load_conf('SMART/SUPPORT_FORMAT', 'jpeg,png,jpg', str)
default_format = ['jpeg', 'png', 'jpg']
SUPPORT_IMG_FORMAT = support_img_format_str.split(',')
if not SUPPORT_IMG_FORMAT:
    SUPPORT_IMG_FORMAT = default_format


